<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html xmlns:th="" lang="zh-CN">
<%@include file="/WEB-INF/pages/base/include.jsp"%>
<body>
<div id="wrapper">
    <%@include file="/WEB-INF/pages/base/menu.jsp"%>
    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h3 class="page-header">商品管理</h3>
            </div>
        </div>
        <div class="row">
            <form class="form-horizontal" data-parsley-validate>
                <div class="col-lg-12 col-md-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">规格基本信息</div>
                        <div class="panel-body">
                            <div class="row">
                                <div class="col-lg-12 col-md-12">
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">规格名称：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="summaryName" class="form-control" placeholder="请输入规格名称"
                                                   required onkeyup = "ValidateValue(this)">
                                        </div>
                                        <div class="col-lg-2 clo-md-2">
                                            <span class="help-block">*必须填写</span>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">规格描述：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="summaryDesc" class="form-control"
                                                   placeholder="请输入规格描述" onkeyup = "ValidateValue(this)">
                                        </div>
                                        <div class="col-lg-2 clo-md-2">
                                            <span class="help-block">*必须填写</span>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="clearfix"></div>
                <button type="button" class="btn btn-primary" onclick="category_create()"
                        style="margin-left:15px;margin-bottom:30px;">发布
                </button>
                <button class="btn btn-default" id="cancel" style="margin-left:15px;margin-bottom:30px;">
                    取消
                </button>
            </form>
        </div>
    </div>
</div>
<script>
	function ValidateValue(textbox) {
		var IllegalString = "[`~!#$^&*()=|{}':;',\\[\\].<>/?~！#￥……&*（）——|{}【】‘；：”“'。，、？-+@&%_]‘’";
		var textboxvalue = textbox.value;
		var index = textboxvalue.length - 1;
		var s = textbox.value.charAt(index);
		if (IllegalString.indexOf(s) >= 0) {
			s = textboxvalue.substring(0, index);
			textbox.value = s;
		}
	}
	var currentI = 0;
	
	function category_create() {
		
    	var baseURL = "${webPath}/productSummary/create";
    	var productId = "${productId}";
        var summaryName = $('#summaryName').val();
        var summaryDesc = $('#summaryDesc').val();
        var json_package = {
       		"head": {},
            "body": {
            	"productId": productId,
                "summaryName": summaryName,
                "summaryDesc": summaryDesc
            }
        };
        $.post(baseURL, {"json_package": JSON.stringify(json_package)}, function (result) {
            if (typeof result == 'string') result = JSON.parse(result);
            if (result.body.result == '0') {
                alert(result.body.description)
                window.location.href="${webPath}toProductSummaryEdit/"+productId+"/"+result.body.productSummaryId;
            } else {
            	alert(result.body.description)
            }
        })
    }
    $(function () {
        $('#cancel').click(function () {
        	var productId = "${productId}";
            window.location.href = "${webPath}toProductSummary/"+productId;
        })
    });
</script>
</body>
</html>